<?php
/**
 * Created by PhpStorm.
 * User: alinejun
 * Date: 2019/1/6
 * Time: 21:01
 */
namespace app\admin\controller;
use app\common\controller\ControllerBase;
use think\Db;

class Goods extends AdminBase{
    /**
     * 用户列表
     */
    protected $goods;
    public function _initialize()
    {
        $this->goods = new \app\common\model\Goods();
        parent::_initialize();
    }
    public function index()
    {
        $seacch_data = input('param.search_data');
        $where = [];
        !empty($seacch_data) and   $where =['name'=>['like','%'.$seacch_data.'%']];
        $list = $this->goods->search($where);
        $this->assign('list', $list);
        return $this->fetch('index');
    }

    public function del()
    {
        $where['id'] = input('id');
        $res = $this->goods->del($where,'status',-1);
        if($res){
            return $this->success('删除成功');
        }else{
            return $this->error('删除失败');
        }
    }

    public function setStatus()
    {
        $this->jump($this->logicAdminBase->setStatus('Goods', $this->param));
    }

    public function add()
    {
        $data = input('param.');
        $category = new \app\common\model\Category();
        $res = $this->goods->editGoods($data);
        $category_list = $category->search();
        IS_POST && $this->jump($res);
        $this->assign('info',['category'=>0,'show_position'=>0]);
        $this->assign('category_list',$category_list);
        return $this->fetch('add');
    }

    public function edit(){
        if(IS_GET){
            $where = input('param.');
            $category = new \app\common\model\Category();
            $category_list = $category->search();
            $this->assign('category_list',$category_list);
            $info = $this->goods->getGoodsById($where);
            !empty($info) && $info['img_ids_array'] = str2arr($info['img_ids']);
            $this->assign('info',$info);
            return $this->fetch('add');
        }
        $data = input('param.');
        $res = $this->goods->editGoods($data);
    }

}